home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / ioctl.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-10-27  |  2.1 KB  |  93 lines

  1. /*
  2.     HOW TO USE IoctlSocket()
  3. */
  4.  
  5. parse arg dev
  6.  
  7. if ~show("L","rexxsupport.library") then
  8.     if ~addlib("rexxsupport.library",0,-30) then do
  9.         say "no rexxsupport.library"
  10.         exit
  11.     end
  12. if ~show("L","rxsocket.library") then
  13.     if ~addlib("rxsocket.library",0,-30) then do
  14.         say "no rxsocket.library"
  15.     exit
  16. end
  17. if ~show("L","rmh.library") then
  18.     if ~addlib("rmh.library",0,-30) then do
  19.         say "no rmh.library"
  20.         exit
  21.     end
  22.  
  23. s=socket("INET","DGRAM")
  24. if s<0 then do
  25.     call err "socket"
  26.     exit
  27. end
  28.  
  29. /* SET the socket as async */
  30. res = IoctlSocket(s,"FIOASYNC",1)
  31. if res<0 then call error "FIOASYNC"
  32. else say "socket is FIOASYNC"
  33.  
  34. /* SET the socket as non blocking */
  35. res = IoctlSocket(s,"FIONBIO",1)
  36. if res<0 then call error "FIONBIO"
  37. else say "socket is FIONBIO"
  38.  
  39.  
  40.  
  41. /* CHECK if at OOB */
  42. res = IoctlSocket(s,"SIOCATMARK","A")
  43. if res<0 then call error "SIOCATMARK"
  44. else say "SIOCATMARK:" a
  45.  
  46. /* GET number of bytes ready to be read */
  47. res = IoctlSocket(s,"FIONREAD","A")
  48. if res<0 then call error "FIONREAD"
  49. else say "FIONREAD:" a
  50.  
  51.  
  52. /* GET vaious interface attributes*/
  53. res = IoctlSocket(s,"SIOCGIFADDR",dev,"A")
  54. if res<0 then say call error "SIOCGIFADDR"
  55. else say "SIOCGIFADDR:" a
  56.  
  57. res = IoctlSocket(s,"SIOCGIFDSTADDR",dev,"A")
  58. if res<0 then call error "SIOCGIFDSTADDR"
  59. else say "SIOCGIFDSTADDR:" a
  60.  
  61. res = IoctlSocket(s,"SIOCGIFBRDADDR",dev,"A")
  62. if res<0 then call error "SIOCGIFBRDADDR"
  63. else say "SIOCGIFBRDADDR:" a
  64.  
  65. res = IoctlSocket(s,"SIOCGIFNETMASK",dev,"A")
  66. if res<0 then call error "SIOCGIFNETMASK"
  67. else say "SIOCGIFNETMASK:" a
  68.  
  69. res = IoctlSocket(s,"SIOCGIFFLAGS",dev,"A")
  70. if res<0 then call error "SIOCGIFFLAGS"
  71. else say "SIOCGIFFLAGS:" a
  72.  
  73. res = IoctlSocket(s,"SIOCGIFMETRIC",dev,"A")
  74. if res<0 then call error "SIOCGIFMETRIC"
  75. else say "SIOCGIFMETRIC:" a
  76.  
  77. res = IoctlSocket(s,"SIOCGIFMTU",dev,"A")
  78. if res<0 then call error "SIOCGIFMTU"
  79. else say "SIOCGIFMTU:" a
  80.  
  81. res = IoctlSocket(s,"SIOCGIFPHYS",dev,"A")
  82. if res<0 then call error "SIOCGIFPHYS"
  83. else say "SIOCGIFPHYS:" a
  84.  
  85. exit
  86.  
  87. error:
  88. parse arg attr
  89.     e=errno()
  90.     if IsLibOn("TTCP") then say "error on" attr":" e
  91.     else say "error on" attr":" errorstring(e)
  92.     return
  93.